<?php
/**
 * Groups module for XOOPS
 *
 * You may not change or alter any portion of this comment or credits
 * of supporting developers from this source code or any supporting source code 
 * which is considered copyrighted (c) material of the original comment or credit authors.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 * @copyright       The Groups Project http://code.google.com/p/groupsforxoops/
 * @license         http://www.fsf.org/copyleft/gpl.html GNU public license
 * @package         groups
 * @since           2.3.0
 * @author          Hui Xiao < xh.8326@gmail.com >
 * @version         $Id: category.php Sat Jul 18 13:22:02 CST 2009
 */

include "header.php";

$op = isset($_GET["op"]) ? $_GET["op"] : "" ;

$cat_handler = xoops_getmodulehandler("category");

switch ($op) {
    case "delcat":
        $cat_id = isset($_GET["cat_id"]) ? intval($_GET["cat_id"]) : 0 ;
        xoops_confirm(array("cat_id"=>$cat_id, "ac"=>"delete"),"action.cat.php","确定删除这个分类！",_SUBMIT);
        break;
	case "create":
	case "edit":
	    $cat_id = isset($_GET["cat_id"]) ? intval($_GET["cat_id"]) : 0 ;
	    $cat_obj = $cat_handler->get($cat_id);
        if ( empty($cat_obj) || !is_object($cat_obj) ) {
            redirect_header("category.php");
        }
		$formUrl = "action.cat.php";
		include(dirname(__FILE__)."../../include/form.cp.edit.category.php");	
		$xoopsTpl->display("db:groups_cp_category_form.html");
        break;
	
	default:
	    $params = array(
	       'order'=>'ASC',
	       'sort'=>'cat_order'
	    );
		$cat_list = array();
    	$cat_objs = $cat_handler->getCategories($params);
    	foreach ( $cat_objs as $k=>$obj ) {
    		$cat_list[$k] = $obj->getValues();
    		$cat_list[$k]["cat_createdate"] = $obj->createDate();
    		$cat_list[$k]["creategroup_perm"] = $obj->createPerm();
    	}
    	$xoopsTpl->assign( array("cat_list"=>$cat_list) );
		$xoopsTpl->display("db:groups_cp_category_list.html");
}
include "footer.php";
?>